import pandas as pd

stu_dic = {'Age':[14,13,13,14,14,12,12,15,13,12,11,14,12,15,16,12,15,11,15],
'Height':[69,56.5,65.3,62.8,63.5,57.3,59.8,62.5,62.5,59,51.3,64.3,56.3,66.5,72,64.8,67,57.5,66.5],
'Name':['Alfred','Alice','Barbara','Carol','Henry','James','Jane','Janet','Jeffrey','John','Joyce','Judy','Louise','Marry','Philip','Robert','Ronald','Thomas','Willam'],
'Sex':['M','F','F','F','M','M','F','F','M','M','F','F','F','F','M','M','M','M','M'],
'Weight':[112.5,84,98,102.5,102.5,83,84.5,112.5,84,99.5,50.5,90,77,112,150,128,133,85,112]}

student = pd.DataFrame(stu_dic)

# 按照性别分类，计算各组别中学生身高和体重的平均值
grouped_by_sex = student.groupby('Sex')[['Height', 'Weight']].mean()
print("按照性别分类的身高和体重平均值：")
print(grouped_by_sex)

# 按照性别与年龄一起分类，计算各组别身高和体重的平均值和中位数
grouped_by_sex_age = student.groupby(['Sex', 'Age'])[['Height', 'Weight']].agg(['mean', 'median'])
print("按照性别与年龄一起分类的身高和体重平均值和中位数：")
print(grouped_by_sex_age)

# 按照学生的年龄升序排序，年龄一样则按照身高降序排序
sorted_students = student.sort_values(by=['Age', 'Height'], ascending=[True, False])
print("按照年龄升序和身高降序排序的学生信息：")
print(sorted_students)